#include "uart_app.h"

uint8_t rx_dat[30];

uint8_t rx_finish_flag = 0;
void UART_proc(void)
{
    if (rx_finish_flag)
    {
        if(rx_dat[0] == 'B' && rx_dat[1] == '1' && rx_dat[2] == '\0')
        {
            if (show_mode)
            {
                show_mode = 0;
            }
            else
            {
                data1.mode ^= 1;
            }
        }
        else if(rx_dat[0] == 'B' && rx_dat[1] == '2' && rx_dat[2] == '\0')
        {
            if (show_mode)
            {
                show_mode = 0;
            }
            else
            {
                if (data1.mode)
                {
                    data1.GEAR++;
                    if (data1.GEAR > 3)
                        data1.GEAR = 3;
                }
            }
        }
        else if(rx_dat[0] == 'B' && rx_dat[1] == '3' && rx_dat[2] == '\0')
        {
            if (show_mode)
            {
                show_mode = 0;
            }
            else
            {
                if (data1.mode)
                {
                    data1.GEAR--;
                    if (data1.GEAR < 1)
                        data1.GEAR = 1;
                }
            }
        }
        else
        {
            printf("NULL");
        }
        memset(rx_dat, 0, sizeof(rx_dat));
        rx_finish_flag = 0;
    }
    

}


void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
{
    rx_finish_flag = 1;
    old_time = HAL_GetTick();
    led_time = old_time;
}
